
package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectConfig {
    /*
    声明direct类型交换机
    */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("hmall.direct");
    }

    /*
    声明队列，名称为 direct.queue1
     */
    @Bean
    public Queue directQueue1() {
        return new Queue("direct.queue1");
    }

    /*
    绑定队列和交换机；路由key 为 red
     */
    @Bean
    public Binding directBinding1(Queue directQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("red");
    }

    /*
    绑定队列和交换机；路由key 为 blue
     */
    @Bean
    public Binding directBinding2(Queue directQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("blue");
    }

    /*
    声明队列，名称为 direct.queue2
     */
    @Bean
    public Queue directQueue2() {
        return new Queue("direct.queue2");
    }

    /*
    绑定队列和交换机；路由key 为 red
     */
    @Bean
    public Binding directBinding3(Queue directQueue2, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue2).to(directExchange).with("red");
    }

    /*
    绑定队列和交换机；路由key 为 yellow
     */
    @Bean
    public Binding directBinding4(Queue directQueue2, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue2).to(directExchange).with("yellow");
    }
}
